const fs = require('fs');
const path = require('path');

// 需要更新的文件列表
const filesToUpdate = [
	'pages/workbench/01task/02jcrwxf.vue',
	'pages/workbench/01task/03jcrwjd.vue',
	'pages/workbench/01task/chouyangdan.vue',
	'pages/workbench/01task/jiancedan.vue',
	'pages/workbench/01task/hechachuzhi.vue',
	'pages/workbench/01task/jiancejigou.vue',
	'pages/workbench/01task/jiancejigouDetail.vue',
	'pages/workbench/01task/kuaijian.vue',
	'pages/workbench/01task/04cqsbfk.vue',
	'pages/workbench/01task/05cpcycx.vue',
	'pages/workbench/01task/016search.vue',
	'pages/workbench/01task/015add.vue',
	'pages/workbench/01task/014editadd.vue',
	'pages/workbench/01task/012edit.vue',
	'pages/workbench/01task/011detail.vue',
	'pages/workbench/01task/01cj.vue',
	'pages/workbench/01task/dianzitongzhi.vue',
	'pages/workbench/07jingjilin/01area.vue',
	'pages/workbench/07jingjilin/02yield.vue',
	'pages/workbench/07jingjilin/03value.vue',
	'pages/workbench/07jingjilin/04classroom.vue',
	'pages/workbench/07jingjilin/04detail.vue',
	'pages/workbench/07jingjilin/05brand.vue',
	'pages/workbench/07jingjilin/06base.vue',
	'pages/workbench/07jingjilin/07policy.vue',
	'pages/workbench/07jingjilin/08tech.vue',
	'pages/workbench/07jingjilin/09activity.vue',
	'pages/workbench/06institution/01audit.vue',
	'pages/workbench/06institution/02passList.vue',
	'pages/workbench/06institution/03actuator.vue',
	'pages/workbench/06institution/05retrospect.vue',
	'pages/workbench/05product/01passInfo.vue',
	'pages/workbench/05product/02unpassInfo.vue',
	'pages/workbench/04question/01advice.vue',
	'pages/workbench/04question/02unpass.vue',
	'pages/workbench/04question/03pending.vue',
	'pages/workbench/04question/04recv.vue',
	'pages/workbench/04question/05sent.vue',
	'pages/workbench/04question/031add.vue',
	'pages/workbench/04question/033select.vue',
	'pages/workbench/04question/041select.vue',
	'pages/workbench/04question/051select.vue',
	'pages/workbench/04question/052detail.vue',
	'pages/workbench/04question/053bufa.vue',
	'pages/workbench/04question/054readstatus.vue',
	'pages/mine/mine.vue',
	'pages/mine/questionAnswer.vue',
	'pages/mine/feedback.vue',
	'pages/index/index.vue',
	'pages/index/01tsjy.vue',
	'subPkg/cjdetail/cjdetail.vue',
	'subPkg/spdetail/spdetail.vue',
	'subPkg/spdetail/spjd.vue',
	'subPkg/jiancejg/addjcjg.vue',
	'subPkg/jiancejg/jcdetail.vue',
	'subPkg/jiancejg/jiancejg.vue',
	'subPkg/trjcbz/trjcbz.vue',
	'subPkg/trjcbz/jcbzxq.vue',
	'subPkg/prodetail/prodetail.vue',
	'subPkg/zzmjsb/zzmjsb.vue',
	'subPkg/zzmjsb/zzclsb.vue',
	'subPkg/zzmjsb/zzczsb.vue',
	'subPkg/zzmjsb/bhgxxsb.vue',
	'subPkg/zzmjsb/cjzcfg.vue',
	'subPkg/zzmjsb/cjzpjs.vue'
];

function updateFile(filePath) {
	const fullPath = path.join(__dirname, filePath);
	
	if (!fs.existsSync(fullPath)) {
		console.log(`文件不存在: ${filePath}`);
		return;
	}
	
	let content = fs.readFileSync(fullPath, 'utf8');
	let updated = false;
	
	// 1. 更新template中的image标签
	if (content.includes('<image src="/static/dingbu.png" class="mine-navbar-bg" mode="aspectFill"></image>')) {
		content = content.replace(
			'<image src="/static/dingbu.png" class="mine-navbar-bg" mode="aspectFill"></image>',
			'<image src="/static/dingbu.png" class="mine-navbar-bg" :style="{ height: navbarHeight + \'rpx\' }" mode="aspectFill"></image>'
		);
		updated = true;
	}
	
	// 2. 添加mixin导入
	if (!content.includes('import navbarMixin')) {
		const scriptMatch = content.match(/<script>([\s\S]*?)<\/script>/);
		if (scriptMatch) {
			const scriptContent = scriptMatch[1];
			if (!scriptContent.includes('navbarMixin')) {
				// 添加import
				const newImport = 'import navbarMixin from \'@/common/navbarMixin\'\n';
				const exportMatch = scriptContent.match(/export default \{/);
				if (exportMatch) {
					const newScript = scriptContent.replace(
						'export default {',
						`${newImport}export default {\n\tmixins: [navbarMixin],`
					);
					content = content.replace(scriptContent, newScript);
					updated = true;
				}
			}
		}
	}
	
	// 3. 移除CSS中的固定高度
	if (content.includes('height: 180rpx;') || content.includes('height: 160rpx;')) {
		content = content.replace(/height:\s*(?:180rpx|160rpx);/g, '');
		updated = true;
	}
	
	if (updated) {
		fs.writeFileSync(fullPath, content, 'utf8');
		console.log(`✅ 已更新: ${filePath}`);
	} else {
		console.log(`⏭️  无需更新: ${filePath}`);
	}
}

// 执行批量更新
console.log('开始批量更新导航栏高度...\n');

filesToUpdate.forEach(file => {
	updateFile(file);
});

console.log('\n批量更新完成！'); 